﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.States.GameState.Entities;
using ElfTyping.Animations;
using Microsoft.Xna.Framework;

namespace ElfTyping.States.GameState.Effects
{
    public class SummonSpellEffect : GameEffect
    {
        const float CastAnimationTime = 0.5f;
        const float SummonAnimationTime = 1.5f;
        const float SpawnTimeAfterCast = 1.0f;

        const float TotalTime = CastAnimationTime + SummonAnimationTime;
        const float TimeLeftToSpawn = TotalTime - SpawnTimeAfterCast;

        SummonerEnemy Summoner { get; set; }

        Animation summoningAnimation = new SummoningAnimation();
        Animation castingAnimation = new CastingSummonAnimation();
        Rectangle summoningRectangle;
        
        public SummonSpellEffect(SummonerEnemy enemyCaster)
        {
            Summoner = enemyCaster;
            summoningRectangle = new Rectangle((int)Summoner.CastingCenterPosition.X - 25, (int)Summoner.CastingCenterPosition.Y - 25, 50, 50);
            CurrentAnimation = castingAnimation;
            DrawBox = Summoner.DrawBox;
            TimeLeft = TotalTime;
        }

        public override void Tick(float dt)
        {
            if (TimeLeft - dt <= TimeLeftToSpawn && TimeLeftToSpawn <= TimeLeft)
            {
                Summoner.SpawnSummon();
            }

            if (TimeLeft > TotalTime - CastAnimationTime) // casting animation
            {
                CurrentAnimation = castingAnimation;
                DrawBox = Summoner.DrawBox;
            }
            else // summoning animation
            {
                CurrentAnimation = summoningAnimation;
                DrawBox = summoningRectangle;
            }

            base.Tick(dt);
        }
    }
}
